package cn.kgc.eduservice.controller.front;

import cn.kgc.commonutils.R;
import cn.kgc.eduservice.entity.EduCourse;
import cn.kgc.eduservice.entity.EduTeacher;
import cn.kgc.eduservice.service.EduCourseService;
import cn.kgc.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName IndexFrontController
 * @Description: TODO
 * @Author :郭建宾
 * @Date 2020/7/13
 * @Version V1.0
 **/
@Api(tags="查询前台")
@RestController
@RequestMapping("/eduservice/indexfront")
//@CrossOrigin
public class IndexFrontController {
    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;

    //查询前8条热门课程，查询前4条名师
    //TODO redis service层
    @GetMapping("index")
    public R index(){
        //查询前8条热门课程
        QueryWrapper<EduCourse>wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> courseList= courseService.list(wrapper);
        //查询前4条名师
        QueryWrapper<EduTeacher>wrapperTeacher = new QueryWrapper<>();
        wrapperTeacher.orderByDesc("id");
        wrapperTeacher.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(wrapperTeacher);

        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }

}
